package com.db.stexchem.client.gui;



import javax.swing.JFrame;
import javax.swing.UIManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.db.stexchem.client.Client;
import com.db.stexchem.client.ClientImpl;
import com.db.stexchem.client.NotificationListener;
import com.db.stexchem.message.ExecutionReport;

/**
 * Entry point for the Client application.
 */
public class ClientGui {
  /** enable logging for this class */
  private final static Logger logger = LoggerFactory.getLogger(ClientGui.class);
  private static ClientGui clientGui;
  private JFrame frame = null;

  public ClientGui(String[] args) throws Exception {
    OrderTableModel orderTableModel = new OrderTableModel();
    final ExecutionTableModel executionTableModel = new ExecutionTableModel(orderTableModel);
    Client application = new ClientImpl();
    application.setNotificationListener(new NotificationListener() {
      
      @Override
      public void onNotificationReceived(ExecutionReport executionReport) {
        executionTableModel.addReport(executionReport);
      }
    });
    frame = new ClientFrame(orderTableModel, executionTableModel, application);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  public JFrame getFrame() {
    return frame;
  }

  public static ClientGui get() {
    return clientGui;
  }

  public static void main(String args[]) throws Exception {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      logger.info(e.getMessage());
    }
    clientGui = new ClientGui(args);
  }

}